(function () {
	var isCanRegist = false;

	function register() {
		$.each($("input"), function (i, item) {
			if ($(this).val() == "") {
				isCanRegist = false;
			}
		})
		if (isCanRegist) {
			$.post("/CHa/user", $("#registForm").serialize(), function (data) {
				if (data != null) {
					window.location.href = "login.html";
				}
				else {
					alert("注册错误，请重新输入个人信息！");
				}
			});
		}
		else {
			alert("注册错误,请重新输入个人信息！");
		}
	}
	window.onload = function () {
		$("#submit").on("click", register);
		$("#repassword").blur(function () {
			var pwd = $("#password").val();
			var repwd = $(this).val();
			if (repwd != pwd) {
				alert("密码不一致！");
				isCanRegist = false;
			}
			else {
				isCanRegist = true;
			}
		})
		$("input").focusout(function () {
			if ($(this).val() == "") {
				if (this.placeholder.indexOf(":")==-1) {
					this.placeholder = this.placeholder + ":" + this.validationMessage;
				}
			}
		})
		$("#account").blur(function () {
			$.get("/CHa/user", {
				account: $("#account").val()
			}, function (data) {
				if (data !=null) {
					alert("用户名重复");
					isCanRegist = false;
				}
				else {
					isCanRegist = true;
				}
			});
		})
	}
})();